import axios from 'axios'
const server = axios.create({
    baseURL: '',
    timeout: 10000
})

//请求拦截

server.interceptors.request.use(config=>{
    if(localStorage.getItem('token')) {
        config.headers.token = localStorage.getItem('token')
    }
    return config
}, err =>{
    Promise.reject(err)
})

//响应拦截
server.interceptors.response.use(res =>{
    return res.data
}, err=>{
    switch (err.status) {
        case 404:
            console.log('页面找不到了');
            break;
        case 500:
            console.log('服务器出错');
        default:
            Promise.reject(err)
            break;
    }
})
export default server